const toString = Object.prototype.toString

export const inBrowser = typeof window !== 'undefined'

export function is(val: unknown, type: string) {
  return toString.call(val) === `[object ${type}]`
}

export function isNumber(val: unknown): val is number {
  return is(val, 'Number')
}

export function isString(val: unknown): val is string {
  return is(val, 'String')
}

export const isFunction = (val: unknown): val is Function => typeof val === 'function'

export function isBoolean(val: unknown): val is boolean {
  return is(val, 'Boolean')
}

export const isObject = (val: any): val is Record<any, any> => {
  return val !== null && is(val, 'Object')
}

export function isArray(val: unknown): val is Array<any> {
  return Array.isArray(val)
}
